unit fmProjSett ;

interface

uses
    Windows,
    Messages,
    SysUtils,
    Variants,
    Classes,
    Graphics,
    Controls,
    Forms,
    Dialogs,
    TBXDkPanels,
    SpTBXControls,
    StdCtrls,
    SpTBXEditors,
    ActnList,
    TB2Item,
    TBX,
    SpTBXItem,
    TBXExtItems,
    TB2ExtItems,
    TB2Dock,
    TB2Toolbar ;

type
    TfrmProjSett = class( TFrame )
        ActionList : TActionList ;
        Action1 : TAction ;
        Action2 : TAction ;
        procedure actPathExecute( Sender : TObject ) ;
        procedure actLibExecute( Sender : TObject ) ;
        procedure cbiUnitsChange( Sender : TObject ; const Text : WideString ) ;
    private
        { Private declarations }
        procedure SetWork( const Value : string ) ;
        function GetWork : string ;
        function GetLibrary : string ;
        procedure SetLibrary( const Value : string ) ;
        function GetPCBHeight : single ;
        function GetPCBWidth : single ;
        function GetUnits : single ;
    public
        { Public declarations }
        constructor Create( AOwner : TComponent ) ; override ;
        destructor Destroy ; override ;

        property WorkPath : string read GetWork write SetWork ;
        property LibPath : string read GetLibrary write SetLibrary ;

        property PCBWidth : single read GetPCBWidth ;
        property PCBHeight : single read GetPCBHeight ;

        property Units : single read GetUnits ;
    end ;

implementation

{$R *.dfm}

uses
    FileCtrl,
    uAppData ;

procedure TfrmProjSett.actPathExecute( Sender : TObject ) ;
var
    iWork           : string ;
begin
    iWork := GetWork ;
    try
        if SelectDirectory( iWork, [ sdAllowCreate, sdPrompt ], 0 ) then
            SetWork( iWork + '\' ) ;
    except
        ELog.Create( 'Failure in setting work directory' ) ;
    end ;
end ;

procedure TfrmProjSett.actLibExecute( Sender : TObject ) ;
var
    iWork           : string ;
begin
    iWork := GetLibrary ;
    try
        if SelectDirectory( iWork, [ sdAllowCreate, sdPrompt ], 0 ) then
            SetLibrary( iWork + '\' ) ;
    except
        ELog.Create( 'Failure in setting library directory' ) ;
    end ;
end ;

constructor TfrmProjSett.Create( AOwner : TComponent ) ;
begin
    inherited ;
    edWorkPath.Text := ExtractFilePath( Application.ExeName ) ;
    edLibPath.Text := ExtractFilePath( Application.ExeName ) + 'Library\' ;
end ;

destructor TfrmProjSett.Destroy ;
begin

    inherited ;
end ;

function TfrmProjSett.GetWork : string ;
begin
    Result := edWorkPath.Text ;
end ;

procedure TfrmProjSett.SetWork( const Value : string ) ;
begin
    edWorkPath.Text := Value ;
end ;

function TfrmProjSett.GetLibrary : string ;
begin
    Result := edLibPath.Text ;
end ;

procedure TfrmProjSett.SetLibrary( const Value : string ) ;
begin
    edLibPath.Text := Value ;
end ;

procedure TfrmProjSett.cbiUnitsChange( Sender : TObject ; const Text : WideString ) ;
begin
    if Text = 'mm' then begin
        ediPCBWidth.PostFix := 'mm' ;
        ediPCBHeight.PostFix := 'mm' ;
        ediViaRing.PostFix := 'mm' ;
        ediViaDrill.PostFix := 'mm' ;
        ediTrackWidth.PostFix := 'mm' ;
        ediTrackSpacing.PostFix := 'mm' ;
    end
    else if Text = 'inch' then begin
        ediPCBWidth.PostFix := '"' ;
        ediPCBHeight.PostFix := '"' ;
        ediViaRing.PostFix := '"' ;
        ediViaDrill.PostFix := '"' ;
        ediTrackWidth.PostFix := '"' ;
        ediTrackSpacing.PostFix := '"' ;
    end ;
end ;

function TfrmProjSett.GetPCBHeight : single ;
begin
    Result := ediPCBWidth.Value * Units ;
end ;

function TfrmProjSett.GetPCBWidth : single ;
begin
    Result := ediPCBHeight.Value * Units ;
end ;

function TfrmProjSett.GetUnits : single ;
begin
    if cbiUnits.Text = 'mm' then
        Result := 1000 / 25.4                     // mm
    else if cbiUnits.Text = '"' then
        Result := 1000                            // inch
    else
        Result := 1 ;                             // mil
end ;

end.

